<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns="http://www.w3.org/1999/xhtml"
	xmlns:n="livcos.org/ns/pm/news"
	xmlns:f="livcos.org/ns/xslt/function"
	xmlns:v="livcos.org/ns/view"
	exclude-result-prefixes="n xs f v">
	
	<xsl:import href="/livcos.org/common/base.xsl"/>
	
	<xsl:template match="n:news">
		<v:style ref="{resolve-uri('styles.css')}"/>
		<xsl:apply-templates select="n:item">
			<xsl:sort select="@date" order="descending"/>
		</xsl:apply-templates>
	</xsl:template>
	
	<xsl:template match="n:item">
		<div id="{@id}" class="newsItem">
    	<xsl:apply-templates select="n:image" />
    	<h1>
        <xsl:choose>
          <xsl:when test="normalize-space(n:link[1]) != ''">
          	<a href="{f:ref-to-uri(n:link[1]/@view, n:link[1], '.html')}">
              <xsl:value-of select="n:title" />
            </a>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="n:title" />
          </xsl:otherwise>
        </xsl:choose>
      </h1>
    	<p>
    		<xsl:apply-templates select="n:description/node()" />
      	<xsl:apply-templates select="@date"/>
      </p>
    </div>
  </xsl:template>

  <xsl:template match="@date">
    <xsl:text>&#160;</xsl:text>
    <span class="pub_date">
      <xsl:value-of select="format-date(xs:date(.), '[D]&#160;[MNn,*-3]&#160;[Y0001]', 'en', (), ())" />
    </span>
  </xsl:template>

	<xsl:template match="@date[normalize-space(.) = '']">
	</xsl:template>
	
	<xsl:template match="n:image[not(node())]">
	</xsl:template>
	
	<xsl:template match="n:image">
		<img class="newsImg" src="{f:ref-to-url(., '.png', 'web')}"/>
	</xsl:template>
	
</xsl:stylesheet>
